<#-- 找回密码第二步 -->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<base href="${baseURL}">
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<title>找回密码 - ${title}</title>
	<meta name="keywords" content="${keywords}"/>
	<meta name="description" content="${description}"/>
	<link rel="shortcut icon" type="image/x-icon" href="${baseURL}${commonPath}images/favicon.ico" media="screen" />
	<link href="${commonPath}css/common.css" type="text/css" rel="stylesheet" >
	<script language="javascript" src="${commonPath}js/tool.js" type="text/javascript"></script>
	<script language="javascript" src="${commonPath}js/ajax.js" type="text/javascript"></script>
	<script language="javascript" src="${commonPath}js/json2.js" type="text/javascript"></script>
	<script src="${commonPath}js/cryptoJS/core.js" language="javascript" type="text/javascript"></script>
	<script src="${commonPath}js/cryptoJS/sha256.js" language="javascript" type="text/javascript"></script>
</head>
<script type="text/javascript" language="javascript"> 
	//确认提交
	function sureSubmit(objForm){
	
		if(allVerification() == false){
			alert("请填好资料再提交");
			return;
		}
		//密码需SHA256加密
		var password = document.getElementById("password").value;
		if(password != ""){
			document.getElementById("password").value = CryptoJS.SHA256(password);
		}
		//密码提示答案需SHA256加密
		var answer = document.getElementById("answer").value;
		if(answer != ""){
			document.getElementById("answer").value = CryptoJS.SHA256(answer);
		}
		
		objForm.submit();
	}
	
	//ajax提交
	function ajaxSubmit(){
		if(allVerification() == false){
			alert("请填好资料再提交");
			return;
		}
		
		var parameter = getParameter();
		if(parameter.indexOf("&") == 0){
			parameter = parameter.substring(1,parameter.length);
		}
		post_request(function(value){
			if(value != ""){
				var returnValue = JSON.parse(value);//JSON转为对象
				for(var key in returnValue){
					if(key == "success"){	
						var success = returnValue[key];	
						if(success == "true"){
							alert("找回密码成功");
							//跳转到登录页
							window.location.href = getBasePath()+"login";
						}
					}else if(key == "error"){
						var errorValue = returnValue[key];
						for(var error in errorValue){
							if(error != ""){
								document.getElementById(error+"_error").innerHTML=errorValue[error];	
							}
						}
					}else if(key == "captchaKey"){//显示验证码	
						var captchaKey = returnValue[key];
						if(captchaKey != ""){
							//设置验证码Key
							if(document.getElementById("captchaKey")!= null){
								document.getElementById("captchaKey").value = captchaKey;
								//设置验证码图片
								replaceCaptcha();
							}	
						}
					}
				}
				
			}	
		},
			"findPassWord/step2?&timestamp=" + new Date().getTime(), true,parameter);
	}
	
	
	
	//组装参数
	function getParameter(){
		var parameter = "";
		//令牌标记
		var token = document.getElementById("token").value;
		parameter += "&token="+token;

		//验证码Key
		var captchaKey = document.getElementById("captchaKey");
		if(captchaKey != null){
			parameter += "&captchaKey="+encodeURIComponent(captchaKey.value);
		}
		//验证码值
		var captchaValue = document.getElementById("captchaValue");
		if(captchaValue != null){
			parameter += "&captchaValue="+encodeURIComponent(captchaValue.value);
		}

		//用户名
		var userName = getUrlParam("userName");
		parameter += "&userName="+encodeURIComponent(userName);
		
		//密码
		var password = document.getElementById("password").value;
		if(password != ""){
			parameter += "&password="+CryptoJS.SHA256(password);
		}
		
		
		//密码提示答案需SHA256加密
		var answer = document.getElementById("answer").value;
		if(answer != ""){
			parameter += "&answer=" + CryptoJS.SHA256(answer);
		}
		
		return parameter;
	}
	
	
	
	//验证全部参数
	function allVerification(){
		var isVerification = true;
		if(verification("password") == false){
			isVerification = false;
		}
		if(verification("confirmPassword") == false){
			isVerification = false;
		}
		if(verification("answer") == false){
			isVerification = false;
		}
		if(verification("captchaValue") == false){
			isVerification = false;
		}
		//清除错误信息
		verification("user");
		return isVerification;
	}

	//验证参数
	function verification(field){
		if(field == "password"){//密码
			var parameter = document.getElementById(field).value;
			if(parameter != ""){
				var parameter_trim = trim(parameter);
				if(parameter_trim != ""){
					if(getStringLeng(parameter_trim) < 6){
						document.getElementById(field+"_error").innerHTML = "密码长度不能小于6位";
						return false;
					}
					if(getStringLeng(parameter_trim) > 20){
						document.getElementById(field+"_error").innerHTML = "密码长度不能大于20位";
						return false;
					}
				}else{
					document.getElementById(field+"_error").innerHTML = "密码不能为空";
					return false;
				}
			}else{
				document.getElementById(field+"_error").innerHTML = "密码不能为空";
				return false;
			}
		}
		if(field == "confirmPassword"){//确认密码
			var password = document.getElementById("password").value;
			
			var parameter = document.getElementById(field).value;
			if(password != parameter){
				document.getElementById(field+"_error").innerHTML = "两次密码不相等";
				return false;
			}
		}
		if(field == "answer"){//密码提示答案
			var parameter = document.getElementById(field).value;
			if(parameter != ""){
				var parameter_trim = trim(parameter);
				if(parameter_trim != ""){
					if(getStringLeng(parameter_trim) < 6){
						document.getElementById(field+"_error").innerHTML = "提示答案长度不能小于6位";
						return false;
					}
					if(getStringLeng(parameter_trim) > 30){
						document.getElementById(field+"_error").innerHTML = "提示答案长度不能大于30位";
						return false;
					}
				}else{
					document.getElementById(field+"_error").innerHTML = "提示答案不能为空";
					return false;
				}
			}else{
				document.getElementById(field+"_error").innerHTML = "提示答案不能为空";
				return false;
			}
		}
		if(field == "captchaValue"){//验证码
			if( document.getElementById("captchaKey") != null){
				var captchaKey = document.getElementById("captchaKey").value;
				var parameter = document.getElementById(field).value;
				if(parameter != ""){
				
					var parameter_trim = trim(parameter);
					if(parameter_trim != ""){
						get_request(function(value){
			            	if(value == "false"){
				            	document.getElementById(field+"_error").innerHTML = "验证码错误";
			            	}
			            },
					 		"userVerification.htm?captchaKey="+captchaKey+"&captchaValue="+parameter_trim+"&timestamp=" + new Date().getTime(), true);
			            	
					}else{
						document.getElementById(field+"_error").innerHTML = "验证码不能为空";
						return false;
					}
				}else{
					document.getElementById(field+"_error").innerHTML = "验证码不能为空";
					return false;
				}
			}
		}
		if(document.getElementById(field+"_error") != null){
			document.getElementById(field+"_error").innerHTML = "";
		}
		return true;
	}
	//更换验证码
	function replaceCaptcha(){
		var captchaKey = document.getElementById("captchaKey").value;
		document.getElementById("captcha").src = "captcha/"+captchaKey+".jpg?" + Math.random(); 
	}
</script> 

<body>
<#-- 引入页头 -->
<@include action="${newPublic_2}"/>
<div class="skeleton">
	<div class="main wrap backgroundModule" >
		<form method="post" action="findPassWord/step2.htm?userName=${url_userName}">
		<!-- 令牌标记 -->
		<input type="hidden" id="token" name="token" value="${token}">
		<div class="findPassWordModule blankTableModule">
		<h2>校验密码提示答案</h2>
		<table class="blankTable" border="0" cellSpacing="2" cellPadding="0" width="500px" >
			<tbody>
				<tr>
		    		<td width="120px" align="right">用户名： </td>
		    		<td align="left" colspan="2">
		    			${user.userName}
		    			<span id="userName_error" class="error">${(error['userName'])!}</span>
		    		</td>
				</tr>
				<tr>
		    		<td width="120px" align="right">密码提示问题： </td>
		    		<td align="left" colspan="2">${user.issue}</td>
				</tr>
				<tr>
		    		<td width="120px" align="right">密码提示答案： </td>
		    		<td align="left" colspan="2">
		    		
		    			<input type="text" id="answer" name="answer" class="formText" autocomplete="off" size="25" maxlength="20" onBlur="verification(this.id)" value=""/>
		    			<span id="answer_error" class="error">${(error['answer'])!}</span>
		    		</td>
				</tr>
				<tr>
					<td width="120px" align="right">新密码： </td>
					<td align="left" colspan="2">
						<input type="password" id="password" name="password" class="formText" autocomplete="off" size="25" maxlength="20" onBlur="verification(this.id)" value=""/>
						<span id="password_error" class="error">${(error['password'])!}</span>
					</td>
				</tr>
				<tr>
					<td width="120px" align="right">确认密码： </td>
					<td colspan="2">
						<input type="password" id="confirmPassword" class="formText" autocomplete="off" size="25" maxlength="20" onBlur="verification(this.id)" value=""/>
						<span id="confirmPassword_error" class="error"></span>
					</td>
					
				</tr>
				<tr>
					<td width="120px" align="right">验证码： </td>
					<td width="10px" >
						<!-- 验证码Key -->
						<input type="hidden" id="captchaKey" name="captchaKey" value="${captchaKey}">
						<input id="captchaValue" name="captchaValue" type="text" class="formText" size="7" maxlength="7" autocomplete="off" onBlur="verification(this.id)"/>		
					</td>
					<td align="left">
						<img id="captcha" src="captcha/${captchaKey!}.jpg" onClick="replaceCaptcha()"/>
						<span id="captchaValue_error" class="error">${(error['captchaValue'])!}</span> 
					
					</td>
				</tr>
				
	
				<tr>
					<td></td>
					<td colspan="2">
						<span id="user_error" class="error">${error['user']}</span>  
						<span class="submitButton"><INPUT type="button" value="提交" onClick="javascript:sureSubmit(this.form);"></span>
						<!-- 
						<span class="submitButton"><INPUT type="button" value="ajax提交" onClick="javascript:ajaxSubmit();"></span>
						 -->
						<span id="token_error" class="error">${error['token']}</span>  
					</td>
				</tr>
			</tbody>
		</table>
		</div>
		</form>
	</div>
</div>
<#--引入页脚-->
<@include action="${newPublic_3}"/>
</body></html>